import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/css/base.css";
import "./assets/css/el-reset.css"
import subMenu from "qf-sub-menu";
import nprogress from "nprogress";
import "nprogress/nprogress.css"
Vue.use (subMenu);
Vue.use (ElementUI);
Vue.config.productionTip = false;
router.beforeEach((to,from,next) =>{
  nprogress.start()
  let token = localStorage.getItem("lex-token") || ""
  if(token) {
    if(store.state.sideMenu.length === 0) {
    store.dispatch("GET_MENULIST").then(() =>{
     return  next({path: top.path})
      })
    }else{
      next()
    }
  }else{
    if(to.path !== "/login"){
      next({path:"/login"})
    }else{
      next()
    }
  }
})

Vue.directive("has", {
  inserted(el, binding) {
    let permission = localStorage.getItem('permissionVuttons') || '[]'
    permission = JSON.parse(permission);

    if(!permission.includes(binding.value)){
      let ElclassName = el.className;
      el.className = ElclassName + " " + "is-disabled"
      el.disabled = true;
    }
  }
})
router.afterEach((to, from) =>{
  nprogress.done()
  let matched = [...to.matched]
  matched.splice(0,1)
  console.log(matched);
  store.commit("SET_BREADCRUMB", matched)
})

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

